home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / install / php-switch.php < prev    next >
PHP Script  |  2004-08-09  |  7KB  |  312 lines

  1. <?php
  2.  
  3. /* 
  4. #### Installer PHP  1.4 RC2  #### 
  5. #### Author: Kay Vogelgesang for www.apachefriends.org 2004 ####  
  6. */    
  7.  
  8. print "\r\n  ########################################################################\n
  9.   # ApacheFriends XAMPP PHP Switch win32 Version 1.0                     #\r\n
  10.   #----------------------------------------------------------------------#\r\n
  11.   # Copyright (c) 2002-2004 Apachefriends                                #\r\n
  12.   #----------------------------------------------------------------------#\r\n
  13.   # Authors: Kay Vogelgesang <kvo@apachefriends.org>                     #\r\n
  14.   #          Oswald Kai Seidler <oswald@apachefriends.org>               #\r\n
  15.   ########################################################################\r\n\r\n"; 
  16.  
  17. $host="127.0.0.1";
  18. $timeout="1";
  19. if (($handle = @fsockopen($host, 80, $errno, $errstr, $timeout)) == true)
  20. {
  21. @fclose($handle);
  22. echo "   The Apache is running! Please stop the Apache before make this procedure!\r\n";
  23. echo "   Der Apache laeuft gerade! Bitte den Apache fuer diese Prozedur stoppen!\r\n";
  24. echo "   PHP Switch exit ...\r\n\r\n";
  25. exit();
  26. }
  27. else
  28. {
  29. @fclose($handle);
  30.  
  31. /// Where I stand? ///
  32. $curdir = getcwd();
  33. list ($partition, $nonpartition) = split (':', $curdir);
  34. list ($partwampp, $directorwampp) = spliti ('\\\install', $curdir);
  35. $awkpart = eregi_replace ("\\\\","\\\\",$partwampp);
  36. $awkpartslash = ereg_replace ("\\\\","/",$partwampp);
  37. $phpdir = $partwampp;
  38. $dir = ereg_replace ("\\\\","/",$partwampp);
  39. $ppartition="$partition:";
  40.  
  41. /// I need the install.sys + update.sys for more xampp informations
  42. $phpversionfile=".phpversion";
  43. $phpversionfileroot=$partwampp."\install\\".$phpversionfile;
  44.  
  45. $phpcurrent=$partwampp."\apache\bin\php.ini";
  46. $php5safety=$partwampp."\php\php5.ini";
  47. $php4safety=$partwampp."\php\php4\php4.ini";
  48. $php4dir=$partwampp."\php\php4";
  49. $php5dir=$partwampp."\php";
  50. $apachebin=$partwampp."\apache\bin";
  51. $php4exe=$partwampp."\php\php4\php.exe";
  52. $php5exe=$partwampp."\php\php.exe";
  53. $phpexe=$partwampp."\apache\bin\php.exe";
  54. $httpconf5=$partwampp."\php\httpd5.conf";
  55. $httpconf4=$partwampp."\php\php4\httpd4.conf";
  56. $httpconf=$partwampp."\apache\conf\httpd.conf";
  57.  
  58. /// XAMPP main directrory is ... 
  59. $substit="\\\\\\\\xampp";
  60. $substitslash="/xampp";
  61.  
  62. /// Globale variables
  63. global $BS; 
  64. $BS = 0;
  65. global $CS; 
  66. $CS = 0;
  67. global $phpcurrentv;
  68.  
  69. $awkexe=".\install\awk.exe";
  70. $awk=".\install\config.awk";
  71.  
  72. $awknewdir="\"".$awkpart."\"";
  73. $awkslashdir="\"".$awkpartslash."\"";
  74.  
  75. if (file_exists($phpversionfileroot)) 
  76. {
  77.     $datei = fopen($phpversionfileroot,'r');
  78.         while(!feof($datei)) 
  79.     {
  80.     $phpcurrentv = fgets($datei,255);
  81.     }
  82.     fclose($datei);
  83. }
  84. else
  85. {
  86. echo "   Cannot find $phpversionfileroot! So i cannot select the current PHP version.\r\n";
  87. echo "   Die $phpversionfileroot! Kann nicht die akuelle PHP Version bestimmen.\r\n";
  88. echo "   PHP Switch exit ...\r\n\r\n";
  89. exit();
  90. }
  91.  
  92. if ($phpcurrentv!="4" && $phpcurrentv!="5")
  93. {
  94. echo "   The PHP version number is not valid.\r\n";
  95. echo "   Die PHP Version Nummer ist ungueltig.\r\n";
  96. echo "   PHP Switch exit ...\r\n\r\n";
  97. exit();
  98.  
  99.  
  100.  
  101. print "\r\n\r\n  The working version in XAMPP is => PHP $phpcurrentv <=\r\n";
  102. print "  The verwendete Version in XAMPP ist => PHP $phpcurrentv <=\r\n\r\n";
  103.  
  104.  
  105. set_time_limit(0);
  106. define('NEWSTDIN',fopen("php://stdin","r"));
  107. while($CS == "0")
  108. {
  109. echo "\n  Type number or 'x' (exit) for selecting your choice!\n";
  110. echo "  Gebe nun Nummer oder 'x' (exit) zum auswaehlen ein!\n\n";
  111. if ($phpcurrentv =="5")
  112.     {
  113.     echo "  4) Switching to PHP 4 (zu PHP 4 wechseln)\n";
  114.     }
  115.     elseif ($phpcurrentv=="4")
  116.     {
  117.     echo "  5) Switching to PHP 5 (zu PHP 5 wechseln)\n";
  118.     }
  119.     else
  120.     {
  121.     echo "  5) Switching to PHP 5 (zu PHP 5 wechseln)\n";
  122.     echo "  4) Switching to PHP 4 (zu PHP 4 wechseln)\n";
  123.     }
  124.     echo "  x) Exit (Beenden)\n";
  125.  
  126. switch(trim(fgets(NEWSTDIN,256)))
  127. {
  128. case 4:
  129. $CS = 4;
  130. echo "\r\n  Starting configure XAMPP with PHP 4 ...\r\n\r\n";
  131. sleep(1);
  132. break;
  133.  
  134. case 5:
  135. $CS = 5;
  136. echo "\r\n  Starting configure XAMPP without PHP 5 ...\r\n\r\n";
  137. sleep(1);
  138. break;
  139.  
  140. case "x":
  141. echo "\r\n  PHP Switch is terminating on demand ...  exit\r\n";
  142. echo "  PHP Switch wurde auf Wunsch abgebrochen ...\r\n\r\n";
  143. sleep(3);
  144. exit();
  145.  
  146. default: 
  147. exit();
  148. }
  149. }
  150. fclose(NEWSTDIN);
  151.  
  152. if ($CS=="4" && $phpcurrentv=="5")
  153. {
  154.     
  155. echo "  Installing PHP4 in XAMPP now!\r\n\r\n";
  156. sleep(1);
  157.  
  158. if (file_exists($phpcurrent)) 
  159.         {
  160.         echo "  Copy the current php.ini to $php5safety ... ";
  161.         copy($phpcurrent,$php5safety);
  162.         echo "done!\r\n";
  163.         }
  164.  
  165.  
  166.  
  167. if (file_exists($php4safety)) 
  168.         {
  169.         echo "  Copy the php4.ini to $phpcurrent ... ";
  170.         copy($php4safety,$phpcurrent);
  171.         echo "done!\r\n\r\n";
  172.         }
  173.  
  174.  
  175.  
  176. if (file_exists($httpconf)) 
  177.         {
  178.         echo "  Safe the $httpconf as $httpconf5 ... ";
  179.         copy($httpconf,$httpconf5);
  180.         echo "done!\r\n\r\n";
  181.         }
  182.  
  183.  
  184. if (file_exists($httpconf4)) 
  185.         {
  186.         echo "  Copy the $httpconf4 to $httpconf ... ";
  187.         copy($httpconf4,$httpconf);
  188.         echo "done!\r\n\r\n";
  189.         }
  190.  
  191.  
  192. echo "  Copy now all php4 dlls to $apachebin\r\n\r\n";
  193.  
  194. $dh= opendir($php4dir);
  195. while($file = readdir ($dh))
  196. {
  197. if (eregi ("\.dll", $file))
  198. {
  199. $php4file=$partwampp."\php\php4\\".$file;
  200. $phpcpfile=$partwampp."\apache\bin\\".$file;
  201. if (file_exists($php4file)) 
  202.         {
  203.         copy($php4file,$phpcpfile);
  204.         echo "$php4file => $phpcpfile\r\n";
  205.         }
  206. }
  207. }
  208. closedir($dh);
  209.  
  210.  
  211. if (file_exists($php4exe)) 
  212.         {
  213.         echo "\r\n  Copy the $php4exe as $phpexe ... ";
  214.         copy($php4exe,$phpexe);
  215.         echo "done!\r\n";
  216.         }
  217.  
  218. echo "  Write the new PHP main version in $phpversionfileroot\r\n";  
  219.     $datei = fopen($phpversionfileroot,'w');
  220.     fputs($datei, "4");
  221.     fclose($datei);
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230. if ($CS=="5" && $phpcurrentv=="4")
  231. {
  232. echo "  Installing PHP5 in XAMPP now!\r\n\r\n";
  233. sleep(1);
  234.  
  235. if (file_exists($phpcurrent)) 
  236.         {
  237.         echo "  Copy the current php.ini to $php4safety ... ";
  238.         copy($phpcurrent,$php4safety);
  239.         echo "done!\r\n";
  240.         }
  241.  
  242.  
  243.  
  244. if (file_exists($php5safety)) 
  245.         {
  246.         echo "  Copy the php5.ini to $phpcurrent ... ";
  247.         copy($php5safety,$phpcurrent);
  248.         echo "done!\r\n\r\n";
  249.         }
  250.  
  251.  
  252.  
  253. if (file_exists($httpconf)) 
  254.         {
  255.         echo "  Safe the $httpconf as $httpconf4 ... ";
  256.         copy($httpconf,$httpconf4);
  257.         echo "done!\r\n\r\n";
  258.         }
  259.  
  260.  
  261. if (file_exists($httpconf5)) 
  262.         {
  263.         echo "  Copy the $httpconf5 to $httpconf ... ";
  264.         copy($httpconf5,$httpconf);
  265.         echo "done!\r\n\r\n";
  266.         }
  267.  
  268.  
  269. echo "  Copy now all php5 dlls to $apachebin\r\n\r\n";
  270.  
  271. $dh= opendir($php5dir);
  272. while($file = readdir ($dh))
  273. {
  274. if (eregi ("\.dll", $file))
  275. {
  276. $php5file=$partwampp."\php\\".$file;
  277. $phpcpfile=$partwampp."\apache\bin\\".$file;
  278. if (file_exists($php5file)) 
  279.         {
  280.         copy($php5file,$phpcpfile);
  281.         echo "$php5file => $phpcpfile\r\n";
  282.         }
  283. }
  284. }
  285. closedir($dh);
  286.  
  287.  
  288. if (file_exists($php5exe)) 
  289.         {
  290.         echo "\r\n  Copy the $php5exe as $phpexe ... ";
  291.         copy($php5exe,$phpexe);
  292.         echo "done!\r\n";
  293.         }
  294.  
  295. echo "  Write the new PHP main version in $phpversionfileroot\r\n";  
  296.     $datei = fopen($phpversionfileroot,'w');
  297.     fputs($datei, "5");
  298.     fclose($datei);
  299.  
  300. }
  301.  
  302. echo "\r\n  OKAY ... PHP SWITCHING WAS SUCCESSFUL";
  303. echo "\r\n\r\n  Now you can start the Apache with PHP $CS !";
  304. echo "\r\n  Nun kannst du den Apache mit PHP $CS starten!";
  305. sleep(1);
  306.  
  307. echo "\r\n\r\n  :-) Kay Vogelgesang (www.apachefriends.org)\r\n\r\n";
  308. exit();
  309. }
  310. ?>
  311.